//
//  VideoPlayViewController.m
//  KingSelected
//
//  Created by 杨鹏 on 2023/11/1.
//

#import "VideoPlayViewController.h"
#import <SJVideoPlayer/SJVideoPlayer.h>

@interface VideoPlayViewController ()

@property (nonatomic, strong) SJVideoPlayer *player;
@end

@implementation VideoPlayViewController

- (void)initDidLoad {
    self.hbd_barHidden = YES;
    _player = [SJVideoPlayer player];
    [_player.defaultEdgeControlLayer.bottomAdapter removeItemForTag:SJEdgeControlLayerBottomItem_Full];
    [_player.defaultEdgeControlLayer.bottomAdapter removeItemForTag:SJEdgeControlLayerBottomItem_Separator];
    [_player.defaultEdgeControlLayer.bottomAdapter exchangeItemForTag:SJEdgeControlLayerBottomItem_DurationTime withItemForTag:SJEdgeControlLayerBottomItem_Progress];
    SJEdgeControlButtonItem *durationItem = [_player.defaultEdgeControlLayer.bottomAdapter itemForTag:SJEdgeControlLayerBottomItem_DurationTime];
    durationItem.insets = SJEdgeInsetsMake(8, 16);
    _player.defaultEdgeControlLayer.bottomContainerView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.6];
    _player.defaultEdgeControlLayer.topContainerView.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.6];
    [_player.defaultEdgeControlLayer.bottomAdapter reload];
    if (@available(iOS 14.0, *)) {
        [_player.defaultEdgeControlLayer.topAdapter removeItemForTag:SJEdgeControlLayerTopItem_PictureInPicture];
        _player.defaultEdgeControlLayer.automaticallyShowsPictureInPictureItem = NO;
    }
    
    NSString *path = [[YPDownloadManager sharedDownloadManager] getImagePathWithUrl:self.videoUrl];
    NSURL *URL = [NSURL fileURLWithPath:path];
    if (path.length <= 0) {
        URL = [NSURL URLWithString:self.videoUrl];
    }
    _player.URLAsset = [[SJVideoPlayerURLAsset alloc] initWithURL:URL];
    [self.view addSubview:_player.view];
    [_player.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

@end
